<template>
  <el-card class="box-card">
    <div slot="header" class="clearfix">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="角色名称">
          <el-input
            v-model="formInline.user"
            placeholder="请输入员工姓名"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <div class="gauge">
            <el-button type="primary" @click="onSubmit">查询</el-button>
            <div class="gauge">
              <el-button type="primary" @click="onNewly">新增角色</el-button>
            </div>
          </div>
        </el-form-item>
      </el-form>
    </div>
    <div class="text item">
      <el-table
        v-loading="loading"
        :data="tableData"
        border
        style="width: 100%"
        max-height="600"
      >
        <el-table-column
          type="index"
          align="center"
          label="序号"
          :index="indexMethod"
          width="60"
        >
        </el-table-column>
        <el-table-column prop="date" align="center" label="角色名称" width="">
        </el-table-column>
        <el-table-column prop="number" align="center" label="菜单权限">
        </el-table-column>
        <el-table-column label="操作" align="center" width="330">
          <template slot-scope="scope">
            <el-button
              size="mini"
              @click="handleEdit(scope.$index, scope.row)"
              class="handList"
              >编辑</el-button
            >
            <el-button
              size="mini"
              type="danger"
              @click="handleDelete(scope.$index, scope.row)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-dialog
      :visible.sync="dialogVisible"
      width="35%"
      :before-close="handleClose"
    >
      <el-form ref="form" :rules="rules" :model="form" label-width="80px">
        <div class="formUser">
          <el-form-item label="角色名称" prop="name">
            <el-input v-model="form.name"></el-input>
          </el-form-item>
        </div>
        <el-form-item label="选择菜单">
          <el-form-item prop="region" class="itemUser">
            <el-select v-model="form.region" placeholder="首页">
              <el-option label="首页" value="shanghai"></el-option>
              <el-option label="角色管理" value="beijing"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="region" class="itemUser">
            <el-select v-model="form.region" placeholder="用户管理">
              <el-option label="用户管理" value="shanghai"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="region" class="itemUser">
            <el-select v-model="form.region" placeholder="商品分类">
              <el-option label="商品分类" value="shanghai"></el-option>
            </el-select>
          </el-form-item>
          <!-- <el-form-item prop="region" class="itemUser">
            <el-select v-model="form.region" placeholder="订单管理">
              <el-option label="订单管理" value="shanghai"></el-option>
            </el-select>
          </el-form-item> -->
          <!-- <el-form-item prop="region" class="itemUser">
            <el-select v-model="form.region" placeholder="财务报表">
              <el-option label="财务报表" value="shanghai"></el-option>
            </el-select>
          </el-form-item> -->
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="confirm">确 定</el-button>
      </span>
    </el-dialog>
  </el-card>
</template>

<script>
export default {
  data() {
    return {
      //弹窗
      dialogVisible: false,
      loading: false,
      token: sessionStorage.getItem("token"),
      formInline: {
        user: "",
        region: "",
      },
      tableData: [
        {
          date: "2016-05-02",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
          img: "",
          number: "12372838238",
          account: "4324798372847",
        },
      ],
      //新增
      form: {
        name: "",
      },
      //分页器
      total: 0,
      limit: 10,
      page: 1,
      //校验
      rules: {
        name: [{ required: true, message: "请输入姓名", trigger: "blur" }],
        region: [
          { required: true, message: "请输入手机号", trigger: "change" },
        ],
        region: [{ required: true, message: "请输入账号", trigger: "change" }],
        region: [{ required: true, message: "请输入密码", trigger: "change" }],
        region: [{ required: true, message: "请选择分类", trigger: "change" }],
        imageUrl: [
          { required: true, message: "请上传头像", trigger: "change" },
        ],
      },
    };
  },
  methods: {
    empty() {
      (this.form.region = ""), (this.form.name = "");
    },
    //查询
    onSubmit() {
      console.log("查询!");
    },
    //重置
    onReset() {
      console.log("重置");
    },
    //新增角色
    onNewly() {
      this.dialogVisible = true;
      console.log("新增客服");
    },
    // 序号排序
    indexMethod(index) {
      // if (this.token < this.limit) {
      //   return this.total - index;
      // } else {
      //   return (
      //     this.total - (this.currentPage - 1) * this.limit - index
      //   );
      // }
    },
    //编辑
    handleEdit(index, row) {
      console.log(index, row);
    },
    //删除
    handleDelete(index, row) {
      console.log(index, row);
    },
    //关闭
    handleClose(done) {
      done();
      this.empty();
    },
    //取消
    cancel() {
      this.dialogVisible = false;
      this.empty();
    },
    //确定
    confirm() {
      this.dialogVisible = false;
    },
  },
};
</script>

<style scoped>
.text {
  font-size: 14px;
}

.item {
  margin-bottom: 18px;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both;
}

.box-card {
  width: 100%;
}

.gauge {
  display: flex;
  margin: 0 20%;
}

.oneLine {
  display: flex;
  justify-content: space-between;
  margin-bottom: 14px;
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}

.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.formUser {
  width: 48%;
}
.itemUser {
  margin-bottom: 20px;
}
</style>